The Code Project
View our advertisers Advertise with us
All Topics, C#, .NET >> C# Controls >> Miscellaneous Controls

A Charting Custom Control using Microsoft OWC
By Catiger

This is a .NET custom control for web-based charting using Office Web Component technology. 
  C#
Windows, .NET (.NET 1.0, .NET 1.1)
Win32, VS (VS.NET2002, VS.NET2003), GDI+
Dev
  Posted 10 Sep 2004 1:18
  Updated 16 Sep 2004 5:37
Articles by this author
29,540 views
Search:
Ultimate Combo
MFC tools $399
Send to a friend
My Profile
My Settings
My Articles
My Bookmarks
Sign out
 


Print Broken Article? Bookmark Discuss
13 votes for this article.
Popularity: 2.52. Rating: 2.26 out of 5.
  • You are signed up for one or more newsletters but unfortunately we are unable to send you emails. Please click here to have an email sent that will allow us to confirm your email address.

Introduction

There are quite a lot commercial or free charting controls available in the market. However, most of the charting requirements are presented with Microsoft Excel charts. In other words, if we can utilize the rich features offered by MS OWC (Office Web Component) including the office charting support, we shall be able to present Microsoft Office charts in web pages.

By employing MS OWC technology, there are basically two approaches to implement the charting control, i.e., server-driven and or client-driven. The server-driven approach is to render the chart at the server side with OWC COM class, through .NET interop. Another one is using OWC ActiveX object. The 2nd approach requires the Office OWC support at the client side and thus incurs the license issue. In this ChartFactory custom control, the server-driven model is adopted. As to how to install the OWC license on the server side, please refer to Microsoft site.

Using the code

Step 1: Adding Control Reference

To use the custom control, you can include the assembly from the toolbox bar in your VS.NET IDE (Add/Remove items -> locate the assembly -> OK). Once done, you can drag and drop that control into ASP.NET forms in any ASPX page or ASCX page.

Step 2: Prepare Chart Data

In order to render the charting, you will have to fill the DataSet first that is required by ChartFactory.AddChartData method. The DataSet instance can only have a single table that must contain three columns having names: "Series", "Group" and "Value". You shall not change the column names as they are referenced by ChartFactory control.

As the ChartFactory doesn't get any chart type information from the DataSet, there shall be some ways to pass the chart type information. It is achieved by passing a parameter ChartFactory.AddChartData method, which however has three types of method signatures:

  • ChartFactory.AddChartData(DataSet dsChart)

    It will choose the DefaultChartType that is set through designer property builder. The chart type will be applied to all series if there are more than one series in the chart.

  • ChartFactory.AddChartData(DataSet dsChart, ChartTypeEnum chartType)

    All series within the chart will have the same chartType.

  • ChartFactory.AddChartData(DataSet dsChart, Hashtable SeriesChartType)

    Each series of the chart may have a different ChartType. Therefore, a mapping between chart series name to chart type are specified in the HashTable.

The ChartFactory.AddChartData method can be called more than once such that more than one chart will be rendered within a single chart space (a term used by MS), and they will all appear in a single GIF image displayed in client HTML.

Render the Chart

Finally, it is to invoke the chart rendering from the application code by calling DataBind() method of the ChartFactory control. The reason why it has to be explicitly invoked is to give more control to the application developers so that they can decide when and where to invoke. Normally, on Page_Load event, ChartFactory.DataBind() has to be called for chart rendering. If there is any postback event, and that would change the DataSet of the ChartFactory or any other properties of it, during the postback event this method will have to be called again.

If any other questions or programming extension requirements, please send to my email box. Thanks. I do all this for the sake of sharing something that can be useful to you.

Appendix: CharTypeEnum Definition

#region CharTypeEnum
 public enum ChartTypeEnum
 {
  Area = 1, /** must start with value=1 as value=0 cause 
               display problem in property browser */
  AreaStacked,
  AreaStacked3D,
  BarStacked,
  Bar3D,
  Column,
  ColumnStacked,
  Column3DStacked,
  Doughnut,
  Line,
  Line3D,
  LineStacked,
  Pie,
  Pie3D,
  PieExploded,
  Pie3DExploded,
  RadarLine,
  ScatterLine
 }
 #endregion

About Catiger


Devoted to IT R&D

8 years of programming experiences

languages: C/C++/VC/C#/java, VB, Delphi

- M.Sc. in Computer Science
- B.Eng in Communication Engineering

Click here to view Catiger's online profile.


Other popular articles:

[Top] Rate this Article for us!     PoorExcellent  

FAQ  Noise tolerance    Search comments  
  View    Per page  
New Message Msgs 1 to 25 of 35 (Total: 35) (Refresh) First Prev Next     
Subject  Author  Date 
  .DLL Requested   barodesign  4:50 6 Apr '06 
  Access Denied in ExportPicture Method   kkrac  9:23 30 Mar '06 
  vb .net version?   taptu  18:28 22 Feb '06 
  DLL needed   gsdtgzesg  22:58 20 Feb '06 
  problem with pie charts   kkrac  16:11 1 Feb '06 
  Re: problem with pie charts   Catiger  2:42 6 Feb '06 
  Re: problem with pie charts   kkrac  7:26 6 Feb '06 
  Ran into a problem with OWC...wondered if you ever observed this behavior with OWC   Arthur Strutzenberg  15:57 17 Jan '06 
  Re: Ran into a problem with OWC...wondered if you ever observed this behavior with OWC   Catiger  3:06 6 Feb '06 
  Re: Ran into a problem with OWC...wondered if you ever observed this behavior with OWC   Arthur Strutzenberg  10:44 6 Feb '06 
  dll please   Mackerel Catcher  3:45 7 Jan '06 
  Re: dll please   Catiger  3:07 6 Feb '06 
  Where is using AIMS.Data.AccessLogic.Common;   renyu732  22:42 17 Dec '05 
  DLL Unconfirmed/Anonymous posting  Your details have been updated  4:08 22 Sep '05 
  DLL & Source Code Requested   fago-de-chao  20:44 12 Aug '05 
  DLL Requested   alirezakhan  4:12 9 May '05 
  ,.DLL Version   alirezakhan  4:04 8 May '05 
  .DLL Version   alirezakhan  4:06 8 May '05 
  Re: .DLL Version Unconfirmed/Anonymous posting  sampahgua  22:07 19 Jun '05 
  Compiled Version   BUXjr  9:46 5 May '05 
  Re: Compiled Version   Catiger  21:33 5 May '05 
  Re: Compiled Version   BUXjr  21:36 5 May '05 
  Re: Compiled Version   Catiger  7:41 6 May '05 
  Re: Compiled Version   BUXjr  7:47 6 May '05 
  Re: Compiled Version   Catiger  3:26 10 May '05 
Last Visit: 19:41 Friday 19th May, 2006 First Prev Next     

General comment    News / Info    Question    Answer    Joke / Game    Admin message


All Topics, C#, .NET >> C# Controls >> Miscellaneous Controls
Updated: 16 Sep 2004 5:37
Article content copyright Catiger, 2004
everything else Copyright © CodeProject, 1999-2006.
Web12 | Advertise on The Code Project | Privacy

The Ultimate Toolbox • ASP Alliance • Developer Fusion • Developersdex • DevGuru • Programmers Heaven • Planet Source Code • Tek-Tips Forums •